package ihm.login;

import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

import configur.PluginFactory;
import exception.FatalException;

public class Authentification extends JFrame {

	private static final long serialVersionUID = 1L;

	public Authentification() {
		super(PluginFactory.INSTANCE.getProperty("screen.app.txt.nom"));

		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			throw new FatalException();
		}

		WindowListener exitListener = new WindowAdapter() {

			@Override
			public void windowClosing(WindowEvent e) {
				int confirm = JOptionPane.showOptionDialog(null,
						"Etes-vous sur de vouloir quitter cette application ?",
						"Confirmation de fermeture", JOptionPane.YES_NO_OPTION,
						JOptionPane.QUESTION_MESSAGE, null, null, null);
				if (confirm == 0) {
					System.exit(0);
				}
			}
		};

		AuthentificationControler controller = new AuthentificationControler(
				this);
		this.add(controller);

		this.setIconImage(Toolkit.getDefaultToolkit().getImage(
				PluginFactory.INSTANCE.getProperty("screen.app.img.icone")));

		this.setResizable(false);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.addWindowListener(exitListener);
		this.pack();
		this.setLocationRelativeTo(null);

		this.setVisible(true);
	}
}
